
<!--A Design by W3layouts
Author: W3layout
Author URL: http://w3layouts.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
-->
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html>
<head>
<title>iQ Online Survey System| Home </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link href="css/style.css" media="all" rel="stylesheet" type="text/css" />
</head>
</head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<!--<script>
function validate()
{
	var id = document.getElementById("survey_id").value;
	
	if(id==null || id =="")
	{
		window.alert("Enter a survey id");
		return false;
	}
	else
	{
		get_survey(id);
	}
}
</script>-->
<script>
$(document).ready(function(){

  var serverAddress = '127.0.0.1';

  $("#submit_id").click(function(){
	  var survey_id= document.getElementById("survey_id").value;
	  var user_id=2;
	  var currentdate =new Date();
	 var date= currentdate.getDate() + "-"
                + (currentdate.getMonth()+1)  + "-" 
                + currentdate.getFullYear()  ;
	
	var request = $.ajax({
		url: "http://" + serverAddress + "/soen-6461-server/surveyParticipation/create",
        type: "GET",
		dataType: "json",
        data : {
				"SurveyParticipation[survey_id]": survey_id, 
				"SurveyParticipation[user_id]" : user_id,
				"SurveyParticipation[started_on]":date
			},
		error: function(){document.getElementById("response").innerHTML="error:survey does not exist";}
    });
	
	request.done(function (response, textStatus, jqXHR){
        
		if(response.code==100)
		{
			var getSurvey = $.ajax({
				url: "http://" + serverAddress + "/soen-6461-server/surveyQA/getQASet",
				type: "GET",
				dataType: "json",
				data : {
						"survey_id": survey_id
						},
				error: function(){document.getElementById("response").innerHTML="error:survey does not exist";}
			});
			
			getSurvey.done(function (response, textStatus, jqXHR){
				if(response.code==100)
				{
					var qaHTML = "";
					var qaList = response.data;
					
					for(var i = 0; i < qaList.length; i++) {
						qaSet = qaList[i];
						var question = qaSet.question;
						var answerChoices = qaSet.answerChoices;
						
						qaHTML += "<div><span>" + (i+1) + ". &nbsp; </span>" + question.text + "</div>";
						
						qaHTML += "<div><ul>";
						for(var j = 0; j < answerChoices.length; j++) {
							var answer = answerChoices[j];
							qaHTML += "<li><input type=radio name='SurveyParticipationDetails[" + i + "][chosen_answer_id]' value='" + answer.id + "'>" + answer.text + "</input></li>";
						}
						qaHTML += "</ul></div>";
					}
					qaHTML += "<div><input type=submit /></div>";
					console.log(qaHTML);
					$('#response').html(qaHTML);
				}
				else
				{
					document.getElementById("response").innerHTML="error:survey does not exist";
				}
			});
		}
		else
		{
			document.getElementById("response").innerHTML="error:survey does not exist";
		}
    });
	
  });
});
</script>
<body>
<div class="header-bg">
<div class="wrap">
	<div class="header">
		<div class="logo">
		  		<a href="index.html"><b><font color="#00FF33" size="+3">iQ Online Survey System</font></b> </a>
		 </div>
	<div class="drp-dwn">
	 	<select onchange="window.location=this.options[this.selectedIndex].value">
        <option value="participate_in_survey.html">Participate In survey </option>
			<option value="index.html">Home</option>
			<option value="signin.html">Signin</option>
			<option value="about.html">About</option>
		</select>
	</div>
	 <div class="clear"></div>
	</div>
</div>
</div>
<div class="fluid_container">
       Thank you for your participation.
  <p>
    <p>
    <div id="response">
    </div>
  </p>
  </p>
     </p>
   </div>
<div class="footer-bg">
<div class="wrap">
<div class="footer">

		<div class="f_grid1">
			<ul class="f_nav">
				<li class="active"><a href="index.html">Home</a></li>
				<li><a href="signin.html">Signin</a></li>
				<li><a href="participate_in_survey.html">Participate In survey</a></li>
				<li><a href="about.html">About</a></li>
			</ul>
			<div class="copy">
				<p class="w3-link">© All Rights Reserved | Design by&nbsp; <a href="http://w3layouts.com/"> W3Layouts</a></p>
			</div>
			<div class="clear"></div>
		</div>
</div>
</div>
</div>
</body>
</html>